package LeetCode;
//给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
public class Num206 {
    public ListNode reverseList(ListNode head) {
//Method One
//        if (head == null || head.next == null) {
//            return head;
//        }
//        ListNode dummyHead = new ListNode(5001);
//        while (head != null) {
//            ListNode node = new ListNode(head.val);
//            node.next = dummyHead.next;
//            dummyHead.next = node;
//            head = head.next;
//        }
//        return dummyHead.next;

//Method Two
        if (head == null || head.next == null) {
            return head;
        }
        ListNode prev = null;
        ListNode cur = head;
        while (cur != null) {
            ListNode next = cur.next;
            cur.next = prev;
            prev = cur;
            cur = next;
        }
        return prev;
    }
}

